package com.wj.blog.controller;

import com.wj.blog.pojo.Music;
import com.wj.blog.service.MusicService;
import com.wj.blog.utils.Page;
import com.wj.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:   wj
 * Date:     2020/4/17 16:26
 * Description: 音乐接口
 */
@RestController
@RequestMapping("/music")
public class MusicControlller {
    @Autowired
    MusicService musicService;

    /**
     * 添加
     * @param music
     * @return
     */
    @PostMapping("/save")
    public Result<Object> save(@RequestBody Music  music){
        musicService.save(music);
        return new Result<>("添加成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Integer id){
        musicService.delete(id);
        return new Result<>("删除成功");
    }

    /**
     * 修改
     * @param music
     * @return
     */
    @PutMapping("/update")
    public Result<Object> update(@RequestBody Music music){
        musicService.update(music);
        return new Result<>("修改成功");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result<Object> getById(@PathVariable Integer id){
       Music music =  musicService.getById(id);
       return new Result<>(music);
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    @PostMapping("/getByPage")
    public Result<List<Music>> getByPage(@RequestBody Page<Music> page){
        List<Music> musics = musicService.getByPage(page);
        return new Result<>(musics);
    }

    /**
     * 前台查询
     * @param page
     * @return
     */
    @PostMapping("/getList")
     public Result<List<Music>> getList(@RequestBody Page<Music> page){
        List<Music> musics = musicService.getList(page);
        return new Result<>(musics);
     }
}
